define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'integral_order/index' + location.search,
                    multi_url: 'ordersmulti',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('id'),operate:false},
                        {field: 'order_no', title: __('订单号'), operate: 'LIKE'},
                        {field: 'mobile', title: __('手机号'),operate: 'LIKE'},
                        {field: 'username', title: __('姓名'),operate: 'LIKE'},
                        {field: 'pay_money', title: __('支付积分'),operate:false},
						{field: 'state', title: __('订单类型'),searchList:{"1":__('精美礼盒'),"2":__('充值卡'),"3":__('酒店住宿'),"4":__('地方特产'),"5":__('线上问诊'),"6":__('健康体检')},formatter: Table.api.formatter.normal},
						{field: 'create_time', title: __('添加时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
						{field: 'status', title: __('订单状态'),searchList:{"1":__('待付款'),"2":__('待发货'),"3":__('待收货'),"4":__('已完成'),"5":__('已取消')},formatter: Table.api.formatter.normal},
						{field: 'is_exchange', title: __('实物是否换货'),searchList:{"1":__('未换货'),"2":__('已申请换货'),"3":__('换货完成')},formatter: Table.api.formatter.normal},
						// {field: 'pay_time', title: __('支付成功时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,buttons: [
        {name: 'detail', text: '详情', title: '详情', icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: 'integral_order/detail'},
		{
			name: 'deliver', 
			text: '发货', 
			title: '发货', 
			classname: 'btn btn-xs btn-success btn-dialog',  // 按钮样式，btn-ajax 代表点击此按钮发送 ajax 请求
			url: 'integral_order/deliver',  // ajax 请求地址
			// 判断该按钮是否显示，row 代表当前行数据
			visible: function (row) {
				// 判断当前行数据中的 status 字段的值是否等于 1
				if (row.status == 2) {
					// return true 代表显示
					return true;
				}
			},
		},
    ],events: Table.api.events.operate, formatter: Table.api.formatter.operate
},
                    ]
                ],
				//禁用默认搜索
				search: false,
				//启用普通表单搜索
				commonSearch: true,
				//可以控制是否默认显示搜索单表,false则隐藏,默认为false
				searchFormVisible: true,
				showSearch: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
		deliver: function(){
		    $(document).on('click','.btn-success',function(){
		        Form.api.submit($("form[role=form]"),function(){
		            window.parent.location.reload();
		        })
		    });
		    Controller.api.bindevent();
		},
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});